package at.fhj.itm11.forum.service.stubs;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import at.fhj.itm11.forum.data.PostDAO;
import at.fhj.itm11.forum.model.Post;

public class PostDAOStub implements PostDAO {

	private Set<Post> repo = new HashSet<Post>();

	@Override
	public Post findById(Long id) {
		for (Post post : repo) {
			if (post.getId().equals(id)) {
				return post;
			}
		}

		return null;
	}

	@Override
	public List<Post> findPostsByTopic(long topicId) {
		List<Post> result = new ArrayList<Post>();

		for (Post post : repo) {
			if (post.getTopic().getId().equals(topicId)) {
				result.add(post);
			}
		}

		return result;
	}

	@Override
	public void persist(Post post) {
		repo.add(post);
	}

	public Set<Post> getRepo() {
		return repo;
	}

	public void setRepo(Set<Post> repo) {
		this.repo = repo;
	}

}
